<%@ page contentType="text/html; charset=utf-8" language="java" 
		 import="java.sql.*" errorPage="" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="javax.jdo.Query" %>
<%@ page import="java.util.List" %>
<%@ page import="shared.MyDateUtil" %>
<%@ page import="shared.PMF" %>
<%@ page import="activity.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>-Search Page-</title>
</head>
<body>
<p><strong>搜尋頁面</strong></p>

<form name="form" method="post" action="testForSearch.jsp">
  <p>請選擇欲搜尋活動日期：
    <label>
    <select name="selectDate">
		<%
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Query query = pm.newQuery(Activity.class);
				
		List<Activity> results = (List<Activity>) query.execute();
		%>
    	<option value="2012/1">Jan</option>		<option value="2012/2">Feb</option>
    	<option value="2012/3">Mar</option>		<option value="2012/4">Apr</option>
    	<option value="2012/5">May</option>		<option value="2012/6">Jun</option>
    	<option value="2012/7">Jul</option>		<option value="2012/8">Aug</option>
    	<option value="2012/9">Sep</option>		<option value="2012/10">Oct</option>
    	<option value="2012/11">Nov</option>	<option value="2012/12">Dec</option>
    </select>
  	</label>     
	</p><p>
    
	<label>  
	  <input type="submit" value="查詢" /><p>
	  <input type="hidden" name="search" value="1" />
    </label></p>
	</form>

	
<table border="1">
<%
PersistenceManager pm2 = PMF.get().getPersistenceManager();
String search = request.getParameter("search");
String select = request.getParameter("selectDate");

if(search != null){
	//Query q = pm2.newQuery("select from activity.Activity_supply where actStart_s =="+select);	
	Query q = pm2.newQuery(activity.Activity_supply.class);
	q.setFilter(":actEnd_s.startsWith(select)");
	try {
	List<Activity_supply> results2 = (List<Activity_supply>) q.execute();
%>
<tr><td>ID</td><td>提供商家名稱</td><td>提供活動名稱</td><td>提供活動點數</td><td>集點開始日期</td><td>集點結束日期</td><td>描述</td></tr>
<%
	if (!results2.isEmpty()) {
        for (Activity_supply act : results2) {      	
        	//if(select.equals(act.getActShop_s())){
%>				
				<tr>
				<td><%=act.getActID_s() %></td>
				<td><%=act.getActShop_s() %></td>
				<td><%=act.getActName_s() %></td>
				<td><%=act.getActPoint_s() %></td>
				<td><%=act.getActStart_s() %></td>
				<td><%=act.getActEnd_s() %></td>
				<td><%=act.getActContent_s()%></td>
				</tr>
<% 		
		//}
      }
   }else
	out.println("查無搜尋結果");	   		
}//try
finally {
    q.closeAll();
		}
}
%>
</table>

<p>&nbsp;</p>
</body>
</html>
